// pages/login/login.js
const $api = require('../../api/index')

Page({

    /**
     * 页面的初始数据
     */
    data: {

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

    },

    /* 快捷登录 */
    quickLogin(e) {
        var that = this;
        if (e.detail.iv) {
            var datas = {}
            datas.iv = e.detail.iv
            datas.encryptedData = e.detail.encryptedData
            $api.loginPhone(datas).then((e) => {
                if (e.data.phone) {
                    var userInfoarr = wx.getStorageSync('userInfo');
                    userInfoarr['telnum'] = e.data.phone;
                    that.setData({
                        userInfo: userInfoarr,
                    });
                    wx.setStorageSync('userInfo', userInfoarr)
                    wx.redirectTo({
                        url: '/pages/faceDetect/faceDetect'
                    })
                }
            }).catch((e) => {
                console.error(e);
            });
        }
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {
        return {
            title: "智慧工地考勤版",
            path: "/pages/index/index",
            imageUrl: "../../images/login_bg.png"
        }
    }
})
